home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-10-05 | 3.5 KB | 99 lines | [TEXT/CWIE] |
- // © Paul B. Beeken, Work In Progress, 1994-5
- // Knowledge Software Consulting.
- //
- // These files are a mindlessly simple wrapper class for the
- // basic XCMD operations. Only one instance of the xcmdBase class is
- // generated per XCMD call but there may be many instances of the XCMDString
- // class. I have used these classes to whip out XCMD/XFCNs within hours of
- // receiving the specs. They work great for me but I will always consider
- // suggestions.
- //
- // Please, please, please, in the unlikely event you should use this stuff
- // for some commercial application I would appreciate you contacting me. If
- // its for your own use, use away. Send email: knowsoft@ios.com
- //
- // As always: this file is presented as is with no warrantees expressed or implied.
- // Swim at your own risk, etc. etc.
-
- #pragma once
- #include "xcmdBase.h"
-
- #ifndef __HYPERXCMD__
- #include <HyperXCmd.h>
- #endif
-
- //
- // Strings form a very important basis for information exchange in
- // hypercard's xcmds and xfcns. It predates the abstract object hierarchy
- // devised for AppleScript. All information is passed using handles to
- // null terminated strings. Hypercard is a bit schitzophrenic (as is my spelling)
- // though. Many
- // of the call back functions require the use of pascal type strings. The
- // creation of a special class to handle these objects is an attempt to deal
- // with this problem in a transparent way.
- //
- // N.B. an xcmd base object must be instantiated before any of the member
- // functions are called. The xcmdBase object sets up the paramPtr which
- // is the vector for the call backs.
- //
-
- class xcmdString {
-
- private:
- static XCmdPtr paramPtr; // allocated when xcmdBase object is instantiated.
-
- Boolean isPascal; // flag as to string type.
- union {
- char* c; // Pointer to c string.
- StringPtr p; // Pointer to pascal string.
- } str;
-
- protected:
- // These functions must be used with great care.
- StringPtr pString( void ); // Bottlenecks for string conversion
- char* cString( void ); // Establishes type and converts if necessary
- operator Handle(); // coerce to a Handle. n.b. user must dispose if not returned to hc.
-
- public:
-
- xcmdString( Handle s );
- ~xcmdString();
-
- // sometimes we need the string explicitly.
- int length( void ) const;
-
- // constructors operators for useful types:
- xcmdString( const xcmdString& s ); // copy constructor
- xcmdString( char* s );
- xcmdString( StringPtr s );
- xcmdString( Boolean v );
- xcmdString( extended v );
- xcmdString( unsigned long v );
- xcmdString( long v, short nd );
- xcmdString( long v );
- xcmdString( Point pt );
- xcmdString( Rect& rct );
-
- // coersion operators for useful types:
- operator Boolean(); // coerece to a Boolean (string is true or false)
- operator Rect(); // coerce to a Rect structure
- operator Point(); // coerce to a Point
- operator long(); // coerce to a signed long value
- operator unsigned long(); // coerce to an unsigned long value
- operator extended(); // coerce to an extended value
- operator StringPtr(); // coerce to a pascal string ptr
- operator char*(); // coerce to a c string ptr
-
- // some important operators
- int contains( xcmdString& s2 ); // offset of s2 in me
-
- xcmdString& operator=( const xcmdString& s2 ); // assignment
- char operator[]( const int i );
- friend
- xcmdString operator&( const xcmdString& s1, const xcmdString& s2 ); // catenation
- friend
- Boolean operator==( const xcmdString& s1, const xcmdString& s2 );
- friend
- Boolean operator!=( const xcmdString& s1, const xcmdString& s2 );
-
- };